// pages/commit/commit.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    firco: "#C2C7CC",
    secco: "#C2C7CC",
    firfo: "normal",
    secfo: "normal",
    detail: "",     //输入框的内容(树洞内容)
  },

  bindTextAreaBlur: function (e) {
    this.data.detail = e.detail.value
  },

  send: function (e) {
    var that = this
    wx.showLoading({
      title: '加载中',
    })

    console.log(that.data.detail)
    //与服务器交互
    wx.request({
      url: getApp().globalData.server + '/index.php/Home/Message/publish_new_message',
      data: {
        user_id: getApp().globalData.user.user_id,
        username: getApp().globalData.user.username,
        face_url: getApp().globalData.user.face_url,
        content: that.data.detail,
      },
      method: "POST",
      header: {
        'content-type': "application/x-www-form-urlencoded"
      },
      success(res) {
        console.log(res.data)
        if (res.data.error_code != 0) {
          wx.showModal({
            title: '抱歉！',
            content: '什么都没有发出去呢- -',
            showCancel: false,
            success: function (res) {}
          })
        }
        else if (res.data.error_code == 0) {
          wx.showModal({
            title: '恭喜~',
            content: '发布成功！',
            showCancel: false,
            success(res) { },
            complete: function (res) {
              wx.reLaunch({
                url: "/pages/square/square"
              })
            }
          })
        }
      },
      fail: function (res) {
        wx.showModal({
          title: '提示!',
          content: '网络异常-_-',
          showCancel: false,
          success: function (res) { }
        })
      },
      complete: function (res) {
        wx.hideLoading()
      }
    })

    setTimeout(function () {
      wx.hideLoading()
    }, 2000)
  },

  /*底部三个按钮的跳转*/
  first_select: function () {
    wx.redirectTo({
      url: '/pages/square/square'
    })
  },

  second_select: function () {

  },

  third_select: function () {
    wx.redirectTo({
      url: '/pages/mine/mine'
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})